package com.example.expinterview.controller;

import com.example.expinterview.dto.CollectDto;
import com.example.expinterview.entity.EiBuy;
import com.example.expinterview.entity.EiCollect;
import com.example.expinterview.entity.ResultBody;
import com.example.expinterview.service.IEiBuyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @classname: BuyController
 * @description: TODO
 * @author: kaiser
 * @date: 2021/10/24 17:43
 * @version: 1.0
 */
@RestController
@RequestMapping("/buy")
@Api(tags = "积分购买面经")
public class BuyController {
    private final IEiBuyService service;

    @Autowired
    public BuyController(IEiBuyService service) {
        this.service = service;
    }

    @PostMapping("/save")
    @ApiOperation(value = "创建")
    public ResultBody save(@RequestBody EiBuy dto) {
        return service.create(dto);
    }

    @GetMapping("/list/{userId}")
    @ApiOperation(value = "根据userId获取积分获取记录")
    public ResultBody list(@PathVariable Long userId) {
        return service.listByUser(userId);
    }

    @PostMapping("/status")
    @ApiOperation(value = "根据用户id和文章id判断是否有可以查看文章")
    public ResultBody status(@RequestBody CollectDto collect) {
        return service.checkCollect(collect);
    }
}
